package com.example.utils;

public class StringUtils {

    public static final String PREF = ",";

    public static Boolean isEmpty(String str){
        return str == null || str.equals("");
    }

    /*****
     *
     * 驼峰命名转下划线命名
     * @param c
     * @return
     */
    public static String camel2under(String c) {
        String separator = "_";
        c = c.replaceAll("([a-z])([A-Z])", "$1" + separator + "$2").toLowerCase();
        return c;
    }

    /*****
     * 下划线命名转驼峰命名
     * @param s
     * @return
     */
    public static String under2camel(String s) {
        String separator = "_";
        String under = "";
        s = s.toLowerCase().replace(separator, " ");
        String sarr[] = s.split(" ");
        for (int i = 0; i < sarr.length; i++) {
            String w = sarr[i].substring(0, 1).toUpperCase() + sarr[i].substring(1);
            under += w;
        }
        return under;
    }

    //首字母转小写
    public static String toLowerCaseFirstOne(String s) {
        if (Character.isLowerCase(s.charAt(0)))
            return s;
        else
            return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString();
    }


    //首字母转大写
    public static String toUpperCaseFirstOne(String s) {
        if (Character.isUpperCase(s.charAt(0)))
            return s;
        else
            return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
    }

    public static String linkString(String leftStr, String linkStr, String rightStr) {
        if (isEmpty(leftStr))
            return rightStr;
        if (isEmpty(rightStr))
            return leftStr;
        return leftStr + linkStr + rightStr;
    }

}
